// import 'package:flustars_flutter3/flustars_flutter3.dart';
import 'package:flutter/material.dart';
import 'package:ls_work/a_elder/models/elder_entity.dart';
import 'package:ls_work/a_yyt/models/gean_entity.dart';
import 'package:ls_work/a_yyt/presenter/gean_presenter.dart';
import 'package:ls_work/a_yyt/widget/ge_an_cell.dart';
import 'package:ls_work/mvp/base_page_state.dart';
import 'package:ls_work/provider/base_list_provider.dart';
import 'package:ls_work/res/colors.dart';
// import 'package:ls_work/res/styles.dart';
import 'package:ls_work/widgets/my_refresh_divider_list.dart';
import 'package:provider/provider.dart';

class HomeGeAnPage extends StatefulWidget {
  final ElderInfo? info;
  HomeGeAnPage({Key? key, this.info});
  @override
  HomeGeAnPageState createState() => HomeGeAnPageState();
}

class HomeGeAnPageState extends BasePageState<HomeGeAnPage, GeAnPresenter>
    with AutomaticKeepAliveClientMixin {
  BaseListProvider<GeAnInfo> provider = BaseListProvider<GeAnInfo>();

  int _page = 1;
  String _keyword = '';
  String _name = '';
  @override
  void initState() {
    _page = 1;
    _name = widget.info != null ? widget.info!.name??"" : '';
    WidgetsBinding.instance.addPostFrameCallback((_) {
      /// 接口请求
      print(presenter);
      presenter.fectData(_keyword, _page, true, _name);
    });
    super.initState();
  }

  @override
  bool get wantKeepAlive => true;
  @override
  Widget build(BuildContext context) {
    super.build(context);
    return ChangeNotifierProvider<BaseListProvider<GeAnInfo>>(
      create: (_) => provider,
      child: Consumer<BaseListProvider<GeAnInfo>>(builder: (_, provider, __) {
        return DeerSeparatedListView(
          key: Key('follow_warning_list'),
          itemCount: provider.list.length,
          stateType: provider.stateType,
          onRefresh: _onRefresh,
          loadMore: _loadMore,
          hasMore: provider.hasMore,
          itemBuilder: (_, index) {
            return GeAnCell(
              info: provider.list[index],
              type: 0,
            );
          },
          separatorBuilder: (_, int index) {
            return Container(
              width: double.infinity,
              height: 1,
              color: Colours.bg_color,
            );
          },
        );
      }),
    );
  }

  // Widget _topView() {
  //   return Container(
  //       width: ScreenUtil.getScreenW(context),
  //       padding: EdgeInsets.all(12),
  //       child: Column(
  //           mainAxisAlignment: MainAxisAlignment.start,
  //           crossAxisAlignment: CrossAxisAlignment.start,
  //           children: <Widget>[
  //             Row(
  //               mainAxisAlignment: MainAxisAlignment.start,
  //               children: <Widget>[
  //                 Text(
  //                   '张奶奶',
  //                   style: TextStyles.textBoldDark16,
  //                 ),
  //                 SizedBox(
  //                   width: 20,
  //                 ),
  //                 Expanded(
  //                   child: Text(
  //                     '2#1-02',
  //                     style: TextStyles.textGray14,
  //                   ),
  //                 ),
  //                 Container(
  //                   padding: EdgeInsets.all(5),
  //                   alignment: Alignment.center,
  //                   decoration: BoxDecoration(
  //                     color: Colors.grey,
  //                     borderRadius: BorderRadius.circular(3)
  //                   ),
  //                   child: Text(
  //                     '未完成',
  //                     style: TextStyle(color: Colors.white, fontSize: 16),
  //                   ),
  //                 )
  //               ],
  //             ),
  //             SizedBox(height: 10,),
  //             Text('发起原因：一堆原因',style: TextStyles.textNormal16,),
  //             SizedBox(height: 10,),
  //             Text('发起人：张护士',style: TextStyles.textNormal16,),
  //             SizedBox(height: 10,),
  //             Text('发起时间：2019-09-08  11：09：09',style: TextStyles.textNormal16,),
  //             SizedBox(height: 10,),
  //             Text('参与人员：张晓晓，李某某，李东东',style: TextStyles.textNormal16,),
  //             SizedBox(height: 10,),
  //             Text('附件：',style: TextStyles.textNormal16,),
  //             SizedBox(height: 10,),
  //             Container(
  //               width: 100,
  //               height: 100,
  //               decoration: BoxDecoration(
  //                 color: Colours.bg_color,
  //                 borderRadius: BorderRadius.circular(5),
  //               ),
  //             ),
  //             SizedBox(height: 20,),
  //             Text('处理记录',style: TextStyles.textBoldDark16,),
  //             SizedBox(height: 30,),
  //             _item(),
  //             Divider(),
  //             _item()
  //           ]));
  // }

  // Widget _item(){
  //   return Column(
  //     mainAxisAlignment: MainAxisAlignment.start,
  //     crossAxisAlignment: CrossAxisAlignment.start,
  //     children: <Widget>[
  //       Row(
  //         mainAxisAlignment: MainAxisAlignment.start,
  //         children: <Widget>[
  //           Expanded(
  //             child: Text('张晓晓',style: TextStyles.textDark16,),
  //           ),
  //           Text('2019-09-09 11:09:09',style: TextStyles.textGray12,),
  //         ],
  //       ),
  //       SizedBox(height: 10,),
  //       Container(
  //         padding: EdgeInsets.all(12),
  //         child: Text('今日张奶奶好像有点不开心，吃饭没有胃口，请社工继续跟进',style: TextStyles.textNormal16,),
  //         decoration: BoxDecoration(
  //           borderRadius: BorderRadius.circular(5),
  //           color: Colours.bg_color
  //         ),
  //       )
  //     ],
  //   );
  // }

  Future _onRefresh() async {
    _page = 1;
    await presenter.fectData(_keyword, _page, true, _name);
  }

  Future _loadMore() async {
    _page++;
    await presenter.fectData(_keyword, _page, true, _name);
  }

  @override
  GeAnPresenter createPresenter() {
    return GeAnPresenter();
  }
}
